package top.chenfu1201.clientApi.config.mns;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitDirectConfig {

    private final static String DIRECT_NAME = "guest-direct";

    @Bean
    Queue queue() {
        return new Queue("hello-guest");
    }

    /**
     * DirectExchange 对象
     * 三个参数分别是名字，重启后是否依然有效以及长期未用时是否删除。
     *
     * @return
     */
    @Bean
    DirectExchange directExchange() {
        DirectExchange directExchange = new DirectExchange(DIRECT_NAME, true, false);
        return directExchange;
    }

    /**
     * Binding 对象，将 Exchange 和 Queue 绑定在一起。
     * DirectExchange 和 Binding 两个 Bean 的配直可以省略掉，
     * 如果使用 DirectExchange，只配 直一个 Queue 的实例即可。
     *
     * @return
     */
    @Bean
    Binding binding() {
//        Binding direct = BindingBuilder.bind(queue()).to(directExchange()).with("direct");
        Binding direct = BindingBuilder.bind(queue()).to(directExchange()).with("topic");
        return direct;
    }

}
